// sub_minsheng_sjts/sjts_batch/sjts_batch.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    repeat: 1,
    dataList: [],
    batchNum: '',
    batchType: '',
    checkType: '待派单',//选中的哪种筛选条件
    checkBtnIshow: true,//流转按钮是否显示
    checkIshow: false, //勾选空是否显示
    DeliveryTo: "外呼员",//判断流转对象
    result: [],//选中的内容
    allChecked: false,//全选框是否勾选
    searchValue: '',//搜索框内容,
    zflxType: 10,//走访类型选中的筛选条件
    option1: [
      { text: '全部', value: '全部' },
    ],
    option2: [
      { text: '全部', value: 30 },
      { text: '已派单', value: 10 },
      { text: '已接通', value: 2 },
      { text: '不需要', value: 3 },
      { text: '他行开户', value: 4 },
      { text: '继续跟进', value: 5 },
      { text: '非企业关键人', value: 6 },
      { text: '未接通', value: 7 },
      { text: '停机', value: 8 },
      { text: '空号', value: 9 },
    ],
    option3: [
      { text: '全部', value: '31' },
      { text: '未接通', value: '12' },
      { text: '不需要', value: '13' },
      { text: '他行开户', value: '14' },
      { text: '继续跟进', value: '15' },
      { text: '已尽调', value: '16' },
      { text: '账户已交付', value: '17' },
    ],
    value1: '全部',
    value2: '',
    value3: '',
  },
  toDetail(e){
    console.log(e,'ee')
    wx.navigateTo({
      url: `/pages/mapDetail/mapDetail?corpKey=${e.currentTarget.dataset.corpcredit}`,
    });
  },
  onChange() {
    console.log('出发了')
  },
  searchChange(e){
    console.log(e,'eee')
    this.setData({
      searchValue:e.detail
    })
  },
  goSearch(){
    console.log(this.data.searchValue)
    this.setData({
      pageNum: 1,
      repeat: 1,
      dataList: []
    })
    this.scrollBottom()
  },
  async getList() {
    if (this.data.checkType == '待派单') {
      let params = {
        batchNum: this.data.batchNum,
        batchType: this.data.batchType,
        pageNum: this.data.pageNum,
        corpName:this.data.searchValue,
        pageSize: 10
      }
      console.log(params, 'paramsparams')
      const res = await getApp().globalData.request(
        "/businessPush/getBatchBusinessCir", params,
        "POST"
      )
      console.log(params, res, '接口返回的值')
      let list = res.data.list
      list.forEach(element => {
        element.checkState = false
        this.data.dataList.push(element)
      });
      this.setData({
        dataList: this.data.dataList,
      })
      this.data.pageNum = this.data.pageNum + 1
    } else if (this.data.checkType == '走访类型' || this.data.checkType == '走访状态') {
      let params = {
        batchNum: this.data.batchNum,
        batchType: this.data.batchType,
        pageNum: this.data.pageNum,
        pageSize: 10,
        corpName:this.data.searchValue,
        status: this.data.zflxType,
      }
      const res = await getApp().globalData.request(
        "/businessPush/getBatchBusinessManage", params,
        "POST"
      )
      console.log( res.msg, '接口返回的值')
      let list = res.data.list
      list.forEach(element => {
        element.checkState = false
        this.data.dataList.push(element)
      });
      this.setData({
        dataList: this.data.dataList,
      })
      this.data.pageNum = this.data.pageNum + 1
    }
  },
  scrollBottom() {
    console.log(this.data.repeat,this.data.pageNum,'到底了')
    if (this.data.repeat == this.data.pageNum) {
      this.data.repeat = this.data.repeat + 1
      this.getList()
    }
  },
  onSwitch1Change1(e) {
    console.log('11')
    this.setData({
      value1: e.detail,
      value2: '',
      value3: '',
      checkIshow: false,
      checkBtnIshow: true,
      DeliveryTo: '外呼员',
      result: [],
      allChecked: false,
      checkType: '待派单',
      dataList: [],
      pageNum: 1,
      repeat: 1
    })
    this.scrollBottom()
  },
  onSwitch1Change2(e) {
    console.log(e, '22')
    this.setData({
      value1: '',
      value2: e.detail,
      value3: '',
      result: [],
      allChecked: false,
      checkType: '走访类型',
      dataList: [],
      pageNum: 1,
      repeat: 1,
      zflxType: e.detail
    })
    if (e.detail == '10') {
      this.setData({
        checkIshow: false,
        checkBtnIshow: true,
        DeliveryTo: '客户经理',

      })
    } else {
      this.setData({
        checkIshow: false,
        checkBtnIshow: false,
      })
    }
    this.scrollBottom()
  },
  showPopup(e){
    console.log(e, 'eee')
    wx.navigateTo({
      url: `/sub_minsheng_sjts/sjts_feedback/sjts_feedback?corpCredit=${e.currentTarget.dataset.corpcredit}&&status=${e.currentTarget.dataset.status}&&remark=${e.currentTarget.dataset.remark}`,
    })
  },
  onSwitch1Change3(e) {
    console.log('33')
    this.setData({
      value1: '',
      value2: '',
      value3: 'e.detail',
      checkIshow: false,
      checkBtnIshow: false,
      checkType: '走访状态',
      dataList: [],
      pageNum: 1,
      repeat: 1,
      zflxType: e.detail
    })
    this.scrollBottom()
  },
  goWander() {
    this.setData({
      checkIshow: true
    })
    // wx.navigateTo({
    //   url: "/sub_minsheng_sjts/sjts_wander/sjts_wander",
    // })
  },
  qxWander() {
    this.setData({
      checkIshow: false
    })
  },
  onChange(e) {
    console.log(e, 'eee')
  },
  goWHY() {
    let resultList = []
    for (let i in this.data.result) {
      for (let a in this.data.dataList) {
        if (this.data.dataList[a].corpCredit == this.data.result[i]) {
          resultList.push(this.data.dataList[a])
        }
      }
    }
    console.log(resultList,'存的值')

    if (this.data.result.length == 0) {
      wx.showToast({
        title: `请勾选企业`,
        icon: 'none'
      })
      return
    }
    wx.setStorageSync('BusinessPushCheckResult', resultList)

    // wx.navigateTo({
    //   url: "/sub_minsheng_sjts/sjts_batch_why/sjts_batch_why",
    // })

    wx.navigateTo({
      url: "/sub_minsheng_sjts/sjts_selectManager/sjts_selectManager?roleType=3",
    })
  },
  goManager() {
    let resultList = []
    for (let i in this.data.result) {
      for (let a in this.data.dataList) {
        if (this.data.dataList[a].corpCredit == this.data.result[i]) {
          resultList.push(this.data.dataList[a])
        }
      }
    }
    console.log(resultList,'存的值')

    if (this.data.result.length == 0) {
      wx.showToast({
        title: `请勾选企业`,
        icon: 'none'
      })
      return
    }
    wx.setStorageSync('BusinessPushCheckResult', resultList)
    wx.navigateTo({
      url: "/sub_minsheng_sjts/sjts_selectManager/sjts_selectManager?roleType=2",
    })
  },
  AllonChange(event) {
    console.log(event, 'eee')
    this.data.result = []
    if (event.detail == false) {
      this.data.dataList.forEach(element => {

      });
    } else {
      this.data.dataList.forEach(element => {
        this.data.result.push(element.corpCredit)
      });
    }

    this.setData({
      allChecked: event.detail,
      result: this.data.result
    });
  },
  onChange(event) {
    console.log(event)


    let allstate = true
    for (let i in this.data.dataList) {
      if (event.detail.includes(this.data.dataList[i].corpCredit) == false) {
        allstate = false
      }
    }
    this.setData({
      result: event.detail,
      allChecked: allstate
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: options.batchNum?'新设企业-第'+options.batchNum+'批次':'新设企业', // 页面标题为传递的标题或默认标题
      success: function () {
        // 设置成功的回调函数
        console.log('标题设置成功');
      },
      fail: function () {
        // 设置失败的回调函数
        console.log('标题设置失败');
      }
    });


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    //当前页的options，啥意思呢，就是你可能某个函数需要刷新，但是他的参数正好是传过来的参数
    console.log(currPage.options, '是啥');
    console.log('dddd')
    this.setData({
      dataList: [],
      pageNum: 1,
      repeat: 1,
      result: [],
      allChecked: false,
      checkBtnIshow: true,
      checkIshow: false,
      value1: '全部',
      value2: '',
      value3: '',
      checkType:'待派单'
    })
    console.log(currPage.options, 'optionsoptions')
    this.setData({
      batchNum: currPage.options.batchNum,
      batchType: currPage.options.batchType
    })
    this.scrollBottom()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})